package com.fishing.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import QL.ButlerGameGetRoomConfigRequest;
import QL.ButlerGameGetRoomConfigResponse;
import QL.ButlerGameGetRoomPlatformDetailRequest;
import QL.ButlerGameGetRoomPlatformDetailResponse;
import QL.ButlerGameGetRoomPlatformSummaryRequest;
import QL.ButlerGameGetRoomPlatformSummaryResponse;
import QL.QLClient;

@Controller
public class RoomLbjController {

	private static QLClient client = new QLClient();
	
	@RequestMapping("room/lbj")
	public ModelAndView lbj(HttpServletRequest request) {
		ModelAndView mav = new ModelAndView("room/config_lbj");
		return mav;
	}
	
	/**
	 * 拉霸机
	 * @param ConfigId 房间ID
	 * */
	@ResponseBody
	@RequestMapping(value="room/lbj/table",produces="text/html;charset=UTF8")
	public Map table(String ServerId,String ConfigId,String GameId,String SiteId,HttpServletRequest request) {
		Map<String,Object> map = new HashMap<>();
		Map<String,Object> mapdata = new HashMap();
		List list = new ArrayList();
		long AllWaterLine = 0;
		long AllFeeGrab = 0;
		long AllBonusPool = 0;
    	try {
			ButlerGameGetRoomPlatformSummaryRequest req = new ButlerGameGetRoomPlatformSummaryRequest();
			req.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
			req.GameId = 3;
			req.SiteId = 0;
			req.ServerId = 0; //游戏服务器
			req.ConfigId = Integer.parseInt(ConfigId);//代表房间ID
			ButlerGameGetRoomPlatformSummaryResponse rsp = new ButlerGameGetRoomPlatformSummaryResponse();
			if (req.ZoneId < 0)
				client.ServerUrl = "http://api2.qq1798.com:8000/router/rest";
			client.Execute(req, rsp);
			for(int i = 0;i < rsp.SummaryList.size();i++) {
				AllWaterLine += rsp.SummaryList.get(i).WaterLine;
				AllFeeGrab += rsp.SummaryList.get(i).FeeGrab;
				AllBonusPool = rsp.SummaryList.get(i).BonusGrab - rsp.SummaryList.get(i).BonusDistribute + rsp.SummaryList.get(i).BonusPush - rsp.SummaryList.get(i).BonusPull;
			}
			map.put("AllWaterLine", AllWaterLine);
			map.put("AllFeeGrab", AllFeeGrab);
			map.put("AllBonusPool", AllBonusPool);
			
			ButlerGameGetRoomConfigRequest req2 = new  ButlerGameGetRoomConfigRequest();
			req2.ZoneId = (Integer)request.getSession().getAttribute("ZoneId");
			req2.GameId = 3;
			req2.SiteId = 0;
			ButlerGameGetRoomConfigResponse rsp2 = new ButlerGameGetRoomConfigResponse();
			client.Execute(req2, rsp2);
			if(rsp2.ErrMsg == "" || rsp2.ErrMsg == null) {
				String difficult[] = rsp2.ConfigList.get((int) req.ConfigId - 1).DifficultyBoundary.split(",");
				map.put("WaterLineLimit", difficult);//当前台子水位线界限
			}
			
			
			list.add(map);
			mapdata.put("status", "200");
			mapdata.put("message", "");
			mapdata.put("count", list.size());
			mapdata.put("data", list);
			return mapdata;
		} catch (Exception e) {
			e.printStackTrace();
		}
		mapdata.put("status", "200");
		mapdata.put("message", "");
		mapdata.put("count", 0);
		mapdata.put("data", "");
		return mapdata;
    }
}
